package xyz.scootaloo.draft;

import org.junit.Test;

import java.util.Arrays;
import java.util.Random;

/**
 * @author flutterdash@qq.com
 * @since 2021/3/26 21:53
 */
public class Case1 {

    public static void main(String[] args) {
        int[] rands = getRandomNumbers(100, 50);
        System.out.println(Arrays.toString(rands));
    }

    private static int[] getRandomNumbers(int bound, int size) {
        int segment = bound / size;
        Random random = new Random();
        int[] randoms = new int[size];

        int base = 0;
        for (int i = 0; i<size; i++) {
            randoms[i] = base + random.nextInt(segment) + 1;
            base = randoms[i];
        }

        return randoms;
    }

    @Test
    public void test() {
        int bound = 100;
        int size = 5;

        Random random = new Random();
        int[] rands = new int[size];

        for (int i = 0; i<size; i++) {
            boolean isRepeat = true;
            int currentRandomNumber;
            while (isRepeat) {
                currentRandomNumber = random.nextInt(bound);
                for (int j = 0; j<i; j++) {
                    if (currentRandomNumber == rands[j]) {
                        break;
                    }
                }
            }
        }
    }

}
